package com.inplaceedit.client.activity.main;

import com.google.gwt.activity.shared.Activity;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.place.shared.Place;
import com.inplaceedit.client.activity.main.contact.ContactDetailsActivity;
import com.inplaceedit.client.activity.main.contact.ContactNewActivity;
import com.inplaceedit.client.application.ApplicationInjector;
import com.inplaceedit.client.place.ContactDetailsPlace;
import com.inplaceedit.client.place.ContactNewPlace;
import com.inplaceedit.client.place.HomePlace;

public class MainActivityMapper implements ActivityMapper {
	private final ApplicationInjector injector;

	public MainActivityMapper(final ApplicationInjector injector) {
		super();
		this.injector = injector;
	}

	@Override
	public Activity getActivity(final Place place) {
		Activity activity = null;
		if (place instanceof HomePlace) {
			activity = injector.getHomeActivity();
		} else if (place instanceof ContactNewPlace) {
			activity = injector.getContactNewActivity();
			((ContactNewActivity) activity).setPlace((ContactNewPlace) place);
		} else if (place instanceof ContactDetailsPlace) {
			activity = injector.getContactDetailsActivity();
			((ContactDetailsActivity) activity)
					.setPlace((ContactDetailsPlace) place);
		}
		return activity;
	}

}
